package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author d11yu
 */
@Controller
@RequestMapping("/hello")
public class RequestMappingController {
    @RequestMapping(
            value = {"/testRequestMapping", "/test"},
//            method ={RequestMethod.GET}
            method = {RequestMethod.POST, RequestMethod.GET}
//            params = {"!username"} // 当前请求的参数中不能有username
//            params = {"username=admin"} // 当前请求的参数中要有username，且其值等于admin
//            params = {"username!=admin"} // 当前请求的参数中要有username，且其值不等于admin
    )
    public String success() {
        return "success";
    }

    @GetMapping("/testGetMapping")
    public String testGetMapping() {
        return "success";
    }

    @RequestMapping(value = "/testPut", method = RequestMethod.PUT)
    // 在浏览器端实现不了put请求
    public String testPut() {
        return "success";
    }

    @RequestMapping(
            value = "/testParamsAndHeaders",
//            params = {"username"}
//            params = {"!username"}
//            params = {"username!=admin","password=123456"}
            params = {"username=admin", "password=123456"},
            /*"header"：要求请求映射所匹配的请求必须携带header请求头信息
                "!header"：要求请求映射所匹配的请求必须不能携带header请求头信息
                "header=value"：要求请求映射所匹配的请求必须携带header请求头信息且header=value
                "header!=value"：要求请求映射所匹配的请求必须携带header请求头信息且header!=value
            */
            headers = {"Host=localhost:8080"}
    )
    public String testParamsAndHeaders() {
        return "success";
    }

    //    @RequestMapping("/a?a/testAnt")
//    @RequestMapping("/a*a/testAnt")
    @RequestMapping("/**/testAnt")
    public String testAnt() {
        return "success";
    }

    @RequestMapping("/testPath/{id}/{username}")
    public String testPath(@PathVariable("id") Integer id, @PathVariable("username") String username) {
        System.out.println("id: " + id + ", username: " + username);
        return "success";
    }
}
